package com.grt192.sensor.create;

import com.grt192.core.Sensor;
import com.iaroc.irobot.IRobotCreate;
import com.iaroc.irobot.IRobotCreateConstants;

/**
 * AngleEncoder polls the a Create for its accumulated angle.
 * 
 * @author ajc
 * 
 */
public class EncoderAngle extends Sensor {

	public static final String ANGLE = "Angle";
	private static final int DEGREES_PER_REVOLUTION = 360;
	private IRobotCreate create;

	/**
	 * Constructs a new EncoderAngle reading from a provided Create
	 * 
	 * @param create
	 *            Robot to read angle from
	 * @param pollTime
	 *            Time between polling angle
	 * @param id
	 */
	public EncoderAngle(IRobotCreate create, int pollTime, String id) {
		this.create = create;
		setSleepTime(pollTime);
		setID(id);

	}

	/**
	 * Polls for Create Angle, kept in bounds of 1 circle in degrees
	 * 
	 * @return
	 */
	public double getAngle() {
		create.sensors(IRobotCreateConstants.SENSORS_ANGLE);
		return create.getAccumulatedAngle() % DEGREES_PER_REVOLUTION;
	}

	public void poll() {
		setState(ANGLE, getAngle());

	}

}
